#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <aclconio.h>
#include <define.h>
#include <transact.h>
#include <tran.h>
#include <gds.h>
#include <sizes.h>
#include "ConfProto.h"
#include "tblutil.h"
#include <\SOFTPAY\Ver30\source\include\sizes.h>
#include <\SOFTPAY\Ver30\HostSrc\citisrc\citiids.h>
#include <\SOFTPAY\Ver30\HostSrc\cpacsrc\cpacids.h>
#include <confio.h>

#include <\SOFTPAY\Ver30\source\include\MIT.h>



static void *storeFromStruct;

static int recordNum;
void registerMIT(void *ptr)
{
	 storeFromStruct = ptr;
}

void *dealWithAddressBoundary(void*address);
int	inLoadMITRecFromStruct (int inRecNumber, void *vdStruct)
{
	int inRet;
	char* tmp = (char*)vdStruct;

	registerMIT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inLoadConfRec(MIT_FILENAME, SIZE_MIT_REC, inRecNumber, vdStruct);

	recordNum = inRecNumber;
	return inRet;
}

void vdRestoreMITRecFromStruct(void *vdStruct)
{
	registerMIT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	memcpy((char *) pvdGetMITRec(), vdStruct, SIZE_MIT_REC);

}

void vdCopyMITRecFromStruct(void *vdStruct)
{
	registerMIT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
		memcpy(vdStruct, (char *) pvdGetMITRec(), SIZE_MIT_REC);

}

int	inSaveMITRecFromStruct (int inRecNumber,  void *vdStruct)
{
	int inRet;

	registerMIT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(MIT_FILENAME, SIZE_MIT_REC, inRecNumber, (char *) vdStruct);

	return inRet;
}

int	inUpdateMITRecFromStruct (void *vdStruct)
{
	int inRet;

	registerMIT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(MIT_FILENAME, SIZE_MIT_REC, recordNum, (char *) vdStruct);

	return inRet;
}

short inGetMerchantNumFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return inGetMerchantNum();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MIT_REC*)vdStruct)->inMerchantNum;
}

void vdSetMerchantNumFromStruct(short inMerchantNum, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetMerchantNum(inMerchantNum);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((MIT_REC*)vdStruct)->inMerchantNum = inMerchantNum;
}

char* szGetMerchantTextFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetMerchantText();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MIT_REC*)vdStruct)->szMerchantText;
}

void vdSetMerchantTextFromStruct(const char* szMerchantText, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetMerchantText(szMerchantText);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((MIT_REC*)vdStruct)->szMerchantText, szMerchantText, sizeof(((MIT_REC*)NULL)->szMerchantText)-1);
}

char* szGetRctHdr1FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetRctHdr1();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MIT_REC*)vdStruct)->szRctHdr1;
}

void vdSetRctHdr1FromStruct(const char* szRctHdr1, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetRctHdr1(szRctHdr1);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((MIT_REC*)vdStruct)->szRctHdr1, szRctHdr1, sizeof(((MIT_REC*)NULL)->szRctHdr1)-1);
}

char* szGetRctHdr6FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetRctHdr6();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MIT_REC*)vdStruct)->szRctHdr6;
}

void vdSetRctHdr6FromStruct(const char* szRctHdr6, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetRctHdr6(szRctHdr6);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((MIT_REC*)vdStruct)->szRctHdr6, szRctHdr6, sizeof(((MIT_REC*)NULL)->szRctHdr6)-1);
}

char* szGetRctFoot4FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetRctFoot4();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MIT_REC*)vdStruct)->szRctFoot4;
}

void vdSetRctFoot4FromStruct(const char* szRctFoot4, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetRctFoot4(szRctFoot4);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((MIT_REC*)vdStruct)->szRctFoot4, szRctFoot4, sizeof(((MIT_REC*)NULL)->szRctFoot4)-1);
}

char* szGetMerchPasswdFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetMerchPasswd();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MIT_REC*)vdStruct)->szMerchPasswd;
}

void vdSetMerchPasswdFromStruct(const char* szMerchPasswd, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetMerchPasswd(szMerchPasswd);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((MIT_REC*)vdStruct)->szMerchPasswd, szMerchPasswd, sizeof(((MIT_REC*)NULL)->szMerchPasswd)-1);
}

char* szGetAutoSettTimeFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetAutoSettTime();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MIT_REC*)vdStruct)->szAutoSettTime;
}

void vdSetAutoSettTimeFromStruct(const char* szAutoSettTime, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetAutoSettTime(szAutoSettTime);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((MIT_REC*)vdStruct)->szAutoSettTime, szAutoSettTime, sizeof(((MIT_REC*)NULL)->szAutoSettTime)-1);
}

char* szGetAutoSettDateFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetAutoSettDate();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MIT_REC*)vdStruct)->szAutoSettDate;
}

void vdSetAutoSettDateFromStruct(const char* szAutoSettDate, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetAutoSettDate(szAutoSettDate);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((MIT_REC*)vdStruct)->szAutoSettDate, szAutoSettDate, sizeof(((MIT_REC*)NULL)->szAutoSettDate)-1);
}

long lnGetInvNumFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return lnGetInvNum();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MIT_REC*)vdStruct)->lnInvNum;
}

void vdSetInvNumFromStruct(long lnInvNum, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetInvNum(lnInvNum);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((MIT_REC*)vdStruct)->lnInvNum = lnInvNum;
}

